package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result list(StudentQueryParam studentQueryParam){
        PageBean pageBean = studentService.page(studentQueryParam);
        return Result.success(pageBean);
    }

    /**
     * 添加学员
     */
    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("添加学生信息{}",student);
        studentService.add(student);
        return Result.success();
    }
    /**
     * 根据id查询学生信息（点击编辑时候的回显功能）
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Student student = studentService.getById(id);
        return Result.success(student);
    }
    /**
     * 修改学员功能
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }

    /**
     * 批量删除学生信息
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("根据id删除学生信息{}",ids);
        studentService.delete(ids);
        return Result.success();
    }
    /**
     * 违纪处理接口**
     */
    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id,
                                  @PathVariable Integer score){
        studentService.updateViolation(id,score);
        return Result.success();

    }
}
